﻿/** \file
* \par Subversion URL:
* \$URL: http://planar-rendering.googlecode.com/svn/trunk/frontend/src/Functions.cs $
* \version \$Rev: 74 $
* \date    \$Date: 2009-04-20 01:12:01 +0000 (Mon, 20 Apr 2009) $
*/

using System;
using System.Runtime.InteropServices;

namespace Frontend
{
	/// <summary>
	/// Default function that describes spatial parameters.
	/// </summary>
	class func_s : Function
	{
		/// <summary>
		/// Set the ranged settings.
		/// </summary>
		/// <param name="gen">The associated generator.</param>
		public override void SetRanges(Generator gen)
		{
			SingleRange(gen, "Sa");
			SingleRange(gen, "Sb");
			SingleRange(gen, "Sc");
			SingleRange(gen, "Sd");
			ranges[0].spatial = true;
			ranges[1].spatial = true;
			ranges[2].spatial = true;
		}
		/// <summary>
		/// Create a new range.
		/// </summary>
		/// <param name="gen">The associated generator.</param>
		/// <param name="name">The range name.</param>
		void SingleRange(Generator gen, string name)
		{
			Range s = gen.AddRange(this);
			s.low = -2;
			s.high = 2;
			s.name = name;
		}
		/// <summary>
		/// Get the function's description.
		/// </summary>
		/// <returns>The description string.</returns>
		public override string GetDescription()
		{
			return "Spatial parameters";
		}
	}

	/// <summary>
	/// Function to take the absolute value of each quaternion vector component.
	/// </summary>
	class func_zabscomps : Function
	{
		/// <summary>
		/// Get the function's description.
		/// </summary>
		/// <returns>The description string.</returns>
		public override string GetDescription()
		{
			return "|a| + |b| i + |c| j + |d| k";
		}
	}

	/// <summary>
	/// Function to square the quaternion.
	/// </summary>
	class func_zpow2 : Function
	{
		/// <summary>
		/// Get the function's description.
		/// </summary>
		/// <returns>The description string.</returns>
		public override string GetDescription()
		{
			return "^2";
		}
	}

	/// <summary>
	/// Function to take the dth power of the quaternion.
	/// </summary>
	class func_zpowd : Function
	{
		/// <summary>
		/// Set the ranged settings.
		/// </summary>
		/// <param name="gen">The associated generator.</param>
		public override void SetRanges(Generator gen)
		{
			Range ex = gen.AddRange(this);
			ex.low = -5;
			ex.high = 5;
			ex.presval = 3;
			ex.name = "Exponent";
		}
		/// <summary>
		/// Get the function's description.
		/// </summary>
		/// <returns>The description string.</returns>
		public override string GetDescription()
		{
			return "^d";
		}
	}

	/// <summary>
	/// Function to add S to the quaternion.
	/// </summary>
	class func_zpluss : Function
	{
		/// <summary>
		/// Get the function's description.
		/// </summary>
		/// <returns>The description string.</returns>
		public override string GetDescription()
		{
			return "+S";
		}
	}

	/// <summary>
	/// Function to add some constant C to the quaternion.
	/// </summary>
	class func_zplusc : Function
	{
		/// <summary>
		/// Set the ranged settings.
		/// </summary>
		/// <param name="gen">The associated generator.</param>
		public override void SetRanges(Generator gen)
		{
			// Use some pretty Julia defaults
			SingleRange(gen, "Ca", -0.745);
			SingleRange(gen, "Cb", 0.113);
			SingleRange(gen, "Cc", 0.01);
			SingleRange(gen, "Cd", 0.01);
		}
		/// <summary>
		/// Create a new range.
		/// </summary>
		/// <param name="gen">The associated generator.</param>
		/// <param name="name">The range name.</param>
		/// <param name="val">The default value of the range.</param>
		void SingleRange(Generator gen, string name, double val)
		{
			Range s = gen.AddRange(this);
			s.low = -2;
			s.high = 2;
			s.presval = val;
			s.name = name;
		}
		/// <summary>
		/// Get the function's description.
		/// </summary>
		/// <returns>The description string.</returns>
		public override string GetDescription()
		{
			return "+C";
		}
	}
}
